//
// See the file COPYING for redistribution information.
//

#include <iostream>
#include <stdint.h>
#include <Naipax.hpp>

using namespace std;
using namespace Naipax;

int main() {
    cerr << "Test for the History module" << endl;

    try {
        History NumHistory("History.db");
        char Key[16];
        string KeyStr;        
        for (uint32_t i = 0; i < 2000; ++i) {
            cout << "Adding " << i << " into history ... " << endl;
            snprintf(Key, 16, "%u", i);
            KeyStr = Key;
            NumHistory.Add(KeyStr);
        }

        for (uint32_t i = 0; i < 3000; i++) {
            cout << "Checking if " << i << " exists in history ... ";
            snprintf(Key, 16, "%u", i);
            KeyStr = Key;
            cout << NumHistory.Has(KeyStr) << endl;
        }

        // Zero-timeout test
        for (uint32_t i = 0; i < 2000; i++) {
            cout << "Adding " << i << " into history ... " << endl;
            snprintf(Key, 16, "%u", i);
            KeyStr = Key;
            NumHistory.Add(KeyStr, 0);
        }

        for (uint32_t i = 0; i < 3000; i++) {
            cout << "Checking if " << i << " exists in history ... ";
            snprintf(Key, 16, "%u", i);
            KeyStr = Key;
            cout << NumHistory.Has(KeyStr) << endl;
        }
    }
    catch (Naipax::Error &E) {
        NAIPAX_PERROR(E.What());
        return -1;
    }

    return 0;
}
